#!/bin/sh

#get this script real directory
SOURCE="$0"
while [ -h "$SOURCE"  ]; do # resolve $SOURCE until the file is no longer a symlink
    this_script_dir="$( cd -P "$( dirname "$SOURCE"  )" && pwd  )"
    SOURCE="$(readlink "$SOURCE")"
    # if $SOURCE was a relative symlink, 
    #we need to resolve it relative to the path 
    #where the symlink file was located
    [[ $SOURCE != /*  ]] && SOURCE="$this_script_dir/$SOURCE"
done
this_script_dir="$( cd -P "$( dirname "$SOURCE"  )" && pwd  )"

cur_dir=`pwd`
log_dir=$HOME/log
cd $log_dir

if [ $# -gt 0 ]; then
    file_name=`ls -tr | grep "ZSmartAgent"|grep "$1" | tail -n 1`
else
    file_name=`ls -tr | grep "ZSmartAgent"| tail -n 1`
fi

if [ -f $file_name ]; then
    printf "you want to trace file is: \"$file_name\"\n"
    sleep 2
    echo starting tail ...
    echo ""
    sleep 2
    tail -f "$file_name"
else
    echo "-- error, $file_name is not a file."
fi
exit 0

